Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove array caching to prevent always returning miss from memory #3

Conversation

rskuipers
Copy link

We were running into issues that on the first load it was giving us a miss even for subsequent calls.
What was happening was that when you retrieve something from cache that doesn't exist, it gets created but the cache item also gets saved to an array for some extra in memory caching. However, this would store the cache item with ->isHit() = false making it so that each subsequent call for retrieving that cache item would still yield a ->isHit() = false until you rerun the request where the array would be empty and it would retrieve the cache item from cache with ->isHit() = true.

This PR removes the memory caching, we should leave the caching to the CacheItemPool.
I've also added a test to cover this case.

When adding the test, another error surfaced so I fixed a type-hint as well, though I'm not fully confident that it's fully covered now, I didn't have time to dive into that area.

@jgivoni jgivoni changed the base branch from master to bugfix/remove-array-caching October 27, 2023 09:25
@jgivoni jgivoni merged commit 19cc7fd into jgivoni:bugfix/remove-array-caching Oct 27, 2023
@jgivoni
Copy link
Owner

jgivoni commented Oct 27, 2023

Thank you Rick, I will look into it.
I tend to agree that caching could be left to the CacheItemPool.
You could set up a 2-level (fast/slow) caching strategy to achieve the behavior I was going for without said bugs.

@rskuipers
Copy link
Author

@jgivoni Thank you for the rapid response!
And indeed, I've used the Symfony Cache Chain Adapter to achieve this, so I could add an ArrayAdapter in front of my RedisAdapter.

jgivoni added a commit that referenced this pull request Oct 27, 2023
@jgivoni
Copy link
Owner

jgivoni commented Oct 27, 2023

Thank you @rskuipers for your contribution!
Merged and tagged 3.0.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants